package com.xc58.highreactor.server.core.loader;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;

import com.xc58.highreactor.server.core.scanner.ClassVisitor;
import com.xc58.highreactor.util.IOUtils;

public class IncrementClassLoader extends ClassLoader{
	
	public Class<?> initClass(String className, byte[] resource) throws IOException{
		return defineClass(className, resource, 0, resource.length);
	}
	
	
	public Class<?> initClass(String className) throws IOException{
		String location = ClassVisitor.name2location.get(className);
		if(location != null){
			FileInputStream file = new FileInputStream(new File(location));
			byte[] bytes = IOUtils.toByteArray(file);
			return defineClass(className, bytes, 0, bytes.length);
		}
		return null;
	}
}
